package com.codelint.gt20post.codec;

import com.tools.Byte2Hex;
import org.apache.log4j.Logger;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolDecoderAdapter;
import org.apache.mina.filter.codec.ProtocolDecoderOutput;

/**
 * Created with IntelliJ IDEA.
 * User: gzhang
 * Date: 5/27/13
 * Time: 9:30 PM
 * To change this template use File | Settings | File Templates.
 */
public class GT20Decoder extends ProtocolDecoderAdapter {
    Logger logger = Logger.getLogger(GT20Decoder.class);

    public void decode(IoSession ioSession, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
        int len = in.remaining();
        byte[] buff = new byte[len];
        for(int i = 0; i < len; i ++){
            buff[i] = in.get();
        }
        logger.info("tcp input stream: " + Byte2Hex.Bytes2HexString(buff));
        out.write(buff);
    }
}
